package entities;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import util.Vector2D;

public class LarvaBeam extends Enemy {

	protected LarvaBoss owner;
	protected Entity target;
	protected int damage;
	protected int maxSpeed;
	protected float aimingStrength;
	protected int lifetime;

	public LarvaBeam(LarvaBoss owner, Vector2D velocity, Entity target)
			throws SlickException {
		super("res/fireball.png");
		this.owner = owner;
		this.damage = 2;
		this.maxHealth = 3;
		this.health = maxHealth;
		this.velocity = velocity;
		this.target = target;
		this.maxSpeed = 250;
		this.aimingStrength = 600;
		this.friction = 0.2f;
		this.lifetime = 5000;
	}

	@Override
	public void update(GameContainer gc, int delta) {
		super.update(gc, delta);
		if (lifetime > 0) {
			Vector2D targetPos = target.pos;
			acceleration = (targetPos.subtract(pos)).getUnitVector().scale(
					aimingStrength);
			if (velocity.getLength() > maxSpeed) {
				velocity = velocity.getUnitVector().scale(maxSpeed);
			}
			velocity = velocity.scale(1.0f - (friction * (delta / 1000.0f)));
			lifetime -= delta;
		}
		
	}
	
//	@Override
//	public void render(GameContainer gc, Graphics g) {
//		Vector2D v1 = new Vector2D(0, -1);
//		Vector2D v2 = velocity.getUnitVector();
//		float angle = v1.getAngle(v2);
//		Image rotatedImage = getImage().copy();
//		rotatedImage.rotate(angle);
//		g.drawImage(rotatedImage, getX(), getY());
//	}

	@Override
	public String getName() {
		return "Larva Beam";
	}

}
